
const g = require('../utils/global');

class PlaneModel {
    constructor() {
        this.type = g.PlaneType.first;
        this.cmd = [];
        // 开始位置
        this.startPos = cc.v2(g.SKY_WIDTH/2, 0);
        // 当前位置
        // this.pos = cc.v2(0, 0);
        // TODO 飞机的动画
        this.status = 0;
        // 一共3条命
        this.attackTimes = 3;
        this.isDead = false;
        // 区别敌机
        this.id = 0;
    }

    /**
     * action function: playTime 开始播放时间，keepTime 动作保持时间，pos 位置
     */

    // 缓慢移动
    delayMove(deltaX, deltaY) {
        this.cmd.push({
            action: g.ActionType.planeDelayMove,
            playTime: g.AnimTime.planeDelayMove,
            keepTime: 0,
            pos: cc.v2(deltaX, deltaY),
        });
    }

    // 移动到另外一个位置
    moveTo(pos, playTime) {
        this.cmd.push({
            action: g.ActionType.planeMoveTo,
            playTime: playTime,
            keepTime: g.AnimTime.planeMove,
            pos: pos,
        });
    }

    // 行动位移
    moveBy(pos, playTime) {
        this.cmd.push({
            action: g.ActionType.planeMoveBy,
            playTime: playTime,
            keepTime: g.AnimTime.planeMove,
            pos: pos,
        });
    }

    toDie(playTime) {
        this.cmd.push({
            action: g.ActionType.toDie,
            playTime: playTime,
            keepTime: g.AnimTime.planeDie,
        });
        this.isDead = true;
    }
    // 被攻击
    attacked(playTime) {
        this.cmd.push({
            action: g.ActionType.planeAttacked,
            playTime: playTime,
            keepTime: g.AnimTime.planeDie,
        });
    }
}

module.exports = {
    PlaneModel,
};